import { create } from 'zustand'
import { persist, createJSONStorage } from 'zustand/middleware'
import { immer } from 'zustand/middleware/immer'

type MonthState = {
  month: number
  setMonth: (value: number) => void
}

export const useMonthStore = create<MonthState>()(
  persist(
    immer((set) => ({
      month: 1,
      setMonth: (value: number) =>
        set((status) => { status.month = value })
    })),
    {
      name: 'month-storage',
      storage: createJSONStorage(() => sessionStorage),
    }
  )
)